package com.jxw.launcher;

import android.app.Service;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Binder;
import android.os.IBinder;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.jht.engine.platsign.PlatSignatureWrapper;
import com.jxw.engine.platsign.MainActivity;
import com.jxw.utils.CommonUtil;
import com.jxw.utils.Logger;
import java.io.PrintStream;
import java.net.SocketException;

/* loaded from: classes.dex */
public class DisableService extends Service {
    public static final String IS_LOCK = "islock";
    public static final String LOCK_MODE_SP = "lockmode";
    private SharedPreferences.Editor editor;
    private View lockView;
    InputMethodManager mImm;
    PlatSignatureWrapper mPlatSignatureWrapper;
    private WindowManager mWindowManager;
    String mcpuid;
    SharedPreferences preference;
    TextView regist_info;
    private View regist_view;
    String serial;
    SharedPreferences spPre;
    private WindowManager.LayoutParams mWindowParams = new WindowManager.LayoutParams();
    public final IBinder mBinder = new LocalBinder();

    /* loaded from: classes.dex */
    class LocalBinder extends Binder {
        LocalBinder() {
        }

        public DisableService getService() {
            return DisableService.this;
        }
    }

    @Override // android.app.Service
    public void onCreate() {
        super.onCreate();
        System.out.println("--onCreate()--");
        this.mPlatSignatureWrapper = new PlatSignatureWrapper(this);
        this.preference = getSharedPreferences("token", 0);
        this.mImm = (InputMethodManager) getSystemService("input_method");
        this.spPre = getSharedPreferences(LOCK_MODE_SP, 0);
        this.editor = this.spPre.edit();
        this.mWindowManager = (WindowManager) getSystemService("window");
        initWindowParams();
        this.lockView = View.inflate(this, R.layout.dialog_disable, null);
        this.lockView.findViewById(R.id.btn_prregist).setOnClickListener(new View.OnClickListener() { // from class: com.jxw.launcher.DisableService.1
            @Override // android.view.View.OnClickListener
            public void onClick(View view) {
                DisableService.this.startActivitySafely();
            }
        });
        this.regist_view = this.lockView.findViewById(R.id.regist_view);
        this.regist_view.setVisibility(8);
        this.lockView.findViewById(R.id.lock_view).setVisibility(0);
        final EditText editText = (EditText) this.regist_view.findViewById(R.id.register_series);
        final EditText editText2 = (EditText) this.regist_view.findViewById(R.id.register_phone);
        final Button button = (Button) this.regist_view.findViewById(R.id.register_go);
        this.regist_info = (TextView) this.regist_view.findViewById(R.id.regist_info);
        View findViewById = this.regist_view.findViewById(R.id.back_btn);
        findViewById.setVisibility(0);
        this.regist_view.findViewById(R.id.regist_content).setVisibility(0);
        findViewById.setOnClickListener(new View.OnClickListener() { // from class: com.jxw.launcher.DisableService.2
            @Override // android.view.View.OnClickListener
            public void onClick(View view) {
                DisableService disableService = DisableService.this;
                disableService.dismissSoftInput(disableService.regist_view);
                editText.setText("");
                editText2.setText("");
                DisableService.this.regist_info.setText("");
                button.setEnabled(true);
                DisableService.this.regist_view.setVisibility(8);
            }
        });
        button.setOnClickListener(new AnonymousClass3(button, editText, editText2));
    }

    /* renamed from: com.jxw.launcher.DisableService$3  reason: invalid class name */
    /* loaded from: classes.dex */
    class AnonymousClass3 implements View.OnClickListener {
        final /* synthetic */ EditText val$mInputSeries;
        final /* synthetic */ Button val$mRegister;
        final /* synthetic */ EditText val$phoneNum;

        AnonymousClass3(Button button, EditText editText, EditText editText2) {
            this.val$mRegister = button;
            this.val$mInputSeries = editText;
            this.val$phoneNum = editText2;
        }

        @Override // android.view.View.OnClickListener
        public void onClick(View view) {
            this.val$mRegister.setEnabled(false);
            final String obj = this.val$mInputSeries.getText().toString();
            DisableService.this.serial = MyApp.getInstance().getUserInfo();
            if ("".equals(DisableService.this.serial)) {
                DisableService disableService = DisableService.this;
                MyApp.getInstance();
                disableService.serial = MyApp.getRKSerial();
            }
            DisableService disableService2 = DisableService.this;
            MyApp.getInstance();
            disableService2.mcpuid = MyApp.getCPUSerial();
            Log.e("zzj", "serial=:" + DisableService.this.serial + ",cpuid=" + DisableService.this.mcpuid);
            if (DisableService.this.mcpuid != null && DisableService.this.mcpuid.contains("000000000000000")) {
                DisableService.this.mcpuid = null;
            }
            if (TextUtils.isEmpty(DisableService.this.serial) && TextUtils.isEmpty(DisableService.this.mcpuid) && (obj == null || obj.isEmpty())) {
                DisableService.this.regist_info.setText(R.string.invalid_series);
                this.val$mRegister.setEnabled(true);
                return;
            }
            new Thread(new Runnable() { // from class: com.jxw.launcher.DisableService.3.1
                @Override // java.lang.Runnable
                public void run() {
                    boolean z;
                    String str = null;
                    for (int i = 0; i < 5; i++) {
                        try {
                            str = MyApp.getInstance().macAddress();
                        } catch (SocketException e) {
                            e.printStackTrace();
                        }
                        if (str != null) {
                            break;
                        }
                    }
                    String str2 = str;
                    if (str2 == null) {
                        AnonymousClass3.this.val$mInputSeries.post(new Runnable() { // from class: com.jxw.launcher.DisableService.3.1.1
                            @Override // java.lang.Runnable
                            public void run() {
                                DisableService.this.regist_info.setText(R.string.read_machineid_fail);
                                AnonymousClass3.this.val$mRegister.setEnabled(true);
                            }
                        });
                    } else if (!TextUtils.isEmpty(obj)) {
                        String obj2 = AnonymousClass3.this.val$phoneNum.getText().toString();
                        try {
                            Long.parseLong(obj);
                            z = true;
                        } catch (Exception e2) {
                            e2.printStackTrace();
                            z = false;
                        }
                        String str3 = obj;
                        if (z) {
                            try {
                                if (str3.length() == 10) {
                                    int charAt = obj.charAt(8) - '0';
                                    int charAt2 = obj.charAt(1) - '0';
                                    int charAt3 = obj.charAt(2) - '0';
                                    int charAt4 = obj.charAt(3) - '0';
                                    if ((obj.charAt(0) - '0') * 2 == charAt && Math.abs(charAt2 - charAt3) == charAt4) {
                                        str3 = MyApp.getInstance().getDeviceSerial();
                                    }
                                }
                            } catch (Exception unused) {
                            }
                        }
                        final String register = MyApp.getInstance().register(1, "A89S", str2, str3, DisableService.this.serial, obj2, DisableService.this.mcpuid);
                        AnonymousClass3.this.val$mInputSeries.post(new Runnable() { // from class: com.jxw.launcher.DisableService.3.1.2
                            @Override // java.lang.Runnable
                            public void run() {
                                Log.e(MainActivity.CERTIFICATION, register + "");
                                AnonymousClass3.this.val$mRegister.setEnabled(true);
                                String[] parseResult = MyApp.getInstance().parseResult(register);
                                if (parseResult != null) {
                                    try {
                                        int parseInt = Integer.parseInt(parseResult[0], 10);
                                        if (parseInt >= 200 && parseInt <= 201) {
                                            if (MyApp.getInstance().saveCertification(parseResult[1])) {
                                                DisableService.this.dismissLock();
                                                DisableService.this.sendBroadcast(new Intent("com.zzj.regist_success"));
                                            } else {
                                                DisableService.this.regist_info.setText(R.string.save_cert_fail);
                                            }
                                        } else {
                                            TextView textView = DisableService.this.regist_info;
                                            textView.setText(DisableService.this.getString(R.string.register_fail) + parseResult[0] + "(" + DisableService.this.getErrorString(parseResult[0]) + ")");
                                        }
                                        return;
                                    } catch (NumberFormatException e3) {
                                        e3.printStackTrace();
                                        return;
                                    }
                                }
                                DisableService.this.regist_info.setText(R.string.network_error);
                            }
                        });
                    } else {
                        AnonymousClass3.this.val$mInputSeries.post(new Runnable() { // from class: com.jxw.launcher.DisableService.3.1.3
                            @Override // java.lang.Runnable
                            public void run() {
                                DisableService.this.regist_info.setText(R.string.invalid_series);
                                AnonymousClass3.this.val$mRegister.setEnabled(true);
                            }
                        });
                    }
                }
            }).start();
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public String getErrorString(String str) {
        int parseInt = Integer.parseInt(str);
        if (parseInt == 901) {
            return getString(R.string.register_error_invalid);
        }
        return getString(MainActivity.ERROR_STRING[(parseInt - 100) % MainActivity.ERROR_STRING.length]);
    }

    @Override // android.app.Service
    public int onStartCommand(Intent intent, int i, int i2) {
        boolean z = this.spPre.getBoolean(IS_LOCK, false);
        PrintStream printStream = System.out;
        printStream.println("--onStartCommand()--" + z);
        if (z) {
            showLock();
            return 1;
        }
        dismissLock();
        return 1;
    }

    @Override // android.app.Service
    public boolean onUnbind(Intent intent) {
        System.out.println("--onUnbind()--");
        return super.onUnbind(intent);
    }

    @Override // android.app.Service
    public IBinder onBind(Intent intent) {
        return this.mBinder;
    }

    private void initWindowParams() {
        WindowManager.LayoutParams layoutParams = this.mWindowParams;
        layoutParams.type = 2038;
        layoutParams.systemUiVisibility = 5894;
        layoutParams.gravity = 17;
    }

    private void show(View view) {
        Logger.getLogger().e("--------------show--------------");
        if (view == null || view.isShown()) {
            return;
        }
        Logger logger = Logger.getLogger();
        logger.e("-" + view.isShown());
        try {
            this.mWindowManager.addView(view, this.mWindowParams);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void showLock() {
        if (this.lockView.isShown()) {
            return;
        }
        CommonUtil.disableStatusBars(getApplicationContext());
        show(this.lockView);
    }

    public void startActivitySafely() {
        ViewGroup.LayoutParams layoutParams = this.regist_view.getLayoutParams();
        double width = this.lockView.getWidth();
        Double.isNaN(width);
        layoutParams.width = (int) (width * 0.7d);
        double height = this.lockView.getHeight();
        Double.isNaN(height);
        layoutParams.height = (int) (height * 0.7d);
        this.regist_view.setLayoutParams(layoutParams);
        this.regist_view.setVisibility(0);
    }

    public void dismissLock() {
        Logger logger = Logger.getLogger();
        logger.e("------dismissLock-----" + this.lockView.isShown());
        if (this.lockView.isShown()) {
            CommonUtil.enableStatusBars(getApplicationContext());
            try {
                this.mWindowManager.removeViewImmediate(this.lockView);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    @Override // android.app.Service
    public void onDestroy() {
        super.onDestroy();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void dismissSoftInput(View view) {
        InputMethodManager inputMethodManager = this.mImm;
        if (inputMethodManager == null || !inputMethodManager.isActive()) {
            return;
        }
        this.mImm.hideSoftInputFromWindow(view.getApplicationWindowToken(), 0);
    }
}
